package com.xbongbong.config;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.parent.abstracts.AbstractSpecialDataAnalysisHelp;
import com.xbongbong.parent.interfaces.logger.OperationLogHandle;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 吴峰
 * @version v1.0
 * @date 2020/4/16 16:31
 * @since v1.0
 */
@Component
public class SpecialDataConfig implements ApplicationContextAware {

    private Map<String, AbstractSpecialDataAnalysisHelp> webDataAnalysisHandleMap;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        webDataAnalysisHandleMap = applicationContext.getBeansOfType(AbstractSpecialDataAnalysisHelp.class);
    }

    @Bean("webDataAnalysisHandleMap")
    public Map<Integer, AbstractSpecialDataAnalysisHelp> webDataAnalysisHandleMap() {
        Map<Integer, AbstractSpecialDataAnalysisHelp> resultMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        this.webDataAnalysisHandleMap.forEach((key, item)->{
            resultMap.put(item.businessType(), item);
        });
        return resultMap;
    }


}
